﻿using System;
using System.Web;
using System.Web.Security;

/// <summary>
/// Descripción breve de BasePage
/// </summary>
namespace IUAP
{
    public class BasePage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            Helpers.SetInputControlsHighlight(this, "highlight", false);
            base.OnLoad(e);
        }

        protected override void OnPreInit(EventArgs e)
        {
            string id = Globals.ThemesSelectorID;
            if (id.Length > 0)
            {
                if (this.Request.Form["__EVENTTARGET"] == id && !string.IsNullOrEmpty(this.Request.Form[id]))
                {
                    this.Theme = this.Request.Form[id];
                    (HttpContext.Current.Profile as ProfileCommon).preferencias.tema = this.Theme;
                }
                else
                {
                    if (!string.IsNullOrEmpty((HttpContext.Current.Profile as ProfileCommon).preferencias.tema))
                        this.Theme = (HttpContext.Current.Profile as ProfileCommon).preferencias.tema;
                }
            }
            base.OnPreInit(e);
        }
        protected void RequestLogin()
        {
            this.Response.Redirect(FormsAuthentication.LoginUrl +
               "?ReturnUrl=" + this.Request.Url.PathAndQuery);
        }
        public string BaseUrl
        {
            get
            {
                string url = this.Request.ApplicationPath;
                if (url.EndsWith("/"))
                    return url;
                else
                    return url + "/";
            }
        }
        public string FullBaseUrl
        {
            get
            {
                return this.Request.Url.AbsoluteUri.Replace(
                   this.Request.Url.PathAndQuery, "") + this.BaseUrl;
            }
        }
    }
}